package com.zjitc.controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zjitc.model.Category;
import com.zjitc.service.CategoryService;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/19 14:55
 * @description:
 */
@Controller
public class CategoryController {
  @Autowired
  private CategoryService categoryService;

  @RequestMapping("/getCategory")
  public void getCategory(HttpServletResponse response) throws IOException {
    List<Category> categories=categoryService.findAllCategory();
    Gson gson=new GsonBuilder().create();
    String json=gson.toJson(categories);
    response.setHeader("Content-type","html/text;charset=utf-8");
    response.getWriter().print(json);
  }

}
